home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Q: How to assign structures?
- Date: 26 Feb 1996 12:56:30 GMT
- Organization: University of Guelph
- Message-ID: <4gsalu$dll@ccshst05.cs.uoguelph.ca>
- NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- I need to assign values to structures in one array from structures in
- another array - in essence I'm copying the whole structure from one array
- to the other. Can I use simple assignment like this:
-
- struct StructName {
- int IVal;
- float FVal;}
-
- struct StructName Array1[5], Array2[5];
- . . .
- for (i=0;i<5;i++) Array1[i] = Array2[i];
- . . .
- And if not that, can I use memcpy() and sizeof() to do the assignment:
-
- for (i=0;i<5;i++) memcpy(&Array2[i],&Array1[i],sizeof(struct StructName));
- Or do I have to assign each element of the structure?
- Toby Hay thay@uoguelph.ca
-